package com.xbdun.service.bmp.facade;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xbdun.common.api.Client;
import com.xbdun.common.api.XbdUnStringResult;
import com.xbdun.common.util.CommonUtil;
import com.xbdun.facade.bmp.exceptions.BmpBizException;
import com.xbdun.facade.bmp.request.system.SysOrgMenusRequest;
import com.xbdun.facade.bmp.service.system.SysOrgMenusFacade;
import com.xbdun.service.bmp.service.system.SysOrgMenusService;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: SysOrgMenusFacadeImpl
 * @Description: 企业菜单信息
 * @author wwq 
 * @date 2017年4月25日
 */
@Component
//@Service(group = DubboConstant.BUSI_PROTAL_GROUP, version = DubboConstant.BUSI_PROTAL_VERSION,retries=DubboConstant.BUSI_PROTAL_RETRY)
@Slf4j
public class SysOrgMenusFacadeImpl implements SysOrgMenusFacade {
	
	@Autowired
	private SysOrgMenusService sysOrgMenusService;

	public XbdUnStringResult impowerOrgMenus(SysOrgMenusRequest request, Client client) {
		XbdUnStringResult result = new XbdUnStringResult();
		try{
			log.info("start - 企业授权菜单新增初始参数,{},{}",request, client);
			
			CommonUtil.validateClient(client);
			if(null==request.getOrgCode()||request.getOrgCode().longValue()<=0){
				throw BmpBizException.PARAM_CHKE_FAIL.newInstance("企业编号不能为空");
			}
			if(CollectionUtils.isEmpty(request.getAddCodes())&&CollectionUtils.isEmpty(request.getCancelCodes())){
				throw BmpBizException.PARAM_CHKE_FAIL.newInstance("授权菜单和取消授权菜单不能同时为空");
			}
			
			//更改企业授权菜单
			sysOrgMenusService.impowerOrgMenus(request);
		} catch (Exception ex) {
			result.setBizException(ex);
			log.error("企业授权菜单新增,入参:{},异常:{}", client, ex);
		} finally {
			log.info("end - 企业授权菜单新增结果:{}", result);
		}
		return result;
	}


	
}
